<?php
App::uses('PaymentAppModel', PAYMENT_CAMELCASENAME.'.Model');
/**
 * PluginPaymentGateway Model
 *
 */
class PaymentGateway extends PaymentAppModel {

/**
 * Use table
 *
 * @var mixed False or table name
 */
	public $useTable = 'plugin_payment_gateway';

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';
	
	public function config($id){
		$data = $this->findById($id);
		return unserialize($data[$this->alias]['config']);
	}
	
	public function saveConfig($data, $id){
		$this->id = $id;
		return $this->saveField('config', serialize($data));
	}
	
	public function gatewayName($id){
		$data = $this->findById($id);
		return $data[$this->alias]['name'];
	}
	
	public function gatewayModel($id){
		$data = $this->findById($id);
		return $data[$this->alias]['model'];
	}
	
	public function activeList(){
		return $this->find('list', array('conditions'=>array('ativo'=>true)));
	}
	
	public function notActiveList(){
		return $this->find('list', array('conditions'=>array('ativo'=>false)));
	}
	
	public function select($id){
		$data = $this->findById($id);
		$this->id = $id;
		return $this->saveField('ativo', !$data[$this->alias]['ativo']);
	}

}
